package com.android.monee.binding.binder;

import com.android.monee.binding.Field;
import com.android.monee.binding.observable.Observable;
import com.android.monee.binding.observer.AbstractObserverImpl;

public abstract class Abstract1WBinder<S,
											So extends Observable<S>,
											Sf extends Field<S, V>,
											T,
											V> {

	protected AbstractObserverImpl<S, T, V> observer;

	public Abstract1WBinder(So observableSource, Sf sourceField, T target) {
		final Abstract1WBinder<S, So, Sf, T, V> that = this;
		
		this.observer = new AbstractObserverImpl<S, T, V>(sourceField, target) {
			@Override
			public void updateTarget(T target, V newVal) {
				that.updateTarget(target, newVal);
			}
		};
		observableSource.addObserver(observer);
		observableSource.notify(sourceField.getClass());
	}

	public abstract void updateTarget(T target, V value);
}
